<?php
    Class Solution{
        /**
         * 228. 汇总区间
         * @param Integer[] $nums
         * @return String[]
         */
        function summaryRanges228($nums) {
            $arr = [];
            foreach($nums as $key => $num) {
                if(!$start && $start !== 0){
                    $start = $num;
                }
                if(!$end || ($num - $nums[$key-1]) == 1){
                    $end = $num;
                }
                if((!$nums[$key+1] && $nums[$key+1] !== 0) || ($nums[$key+1] - $num) !== 1){
                    if($start == $end){
                        $arr[] = (string)$start;
                    }else{
                        $arr[] = $start . '->' . $end;
                    }
                    $start = null;
                    $end   = null;
                }
            }

            return $arr;
        }

        /**
         * 231. 2 的幂
         * @param Integer $n
         * @return Boolean
         */
        function isPowerOfTwo231($n) {
            if($n <= 0){
                return false;
            }
            while($n > 1){
                if(($n % 2) != 0){
                    return false;
                }
                $n = $n / 2;
            }

            return true;
        }

        /**
         * 242. 有效的字母异位词
         * @param String $s
         * @param String $t
         * @return Boolean
         */
        function isAnagram242($s, $t) {
            $lenA = strlen($s);
            if($lenA != strlen($t)){
                return false;
            }
            $map = [];
            for($i = 0; $i < $lenA; $i++) {
                if(!$map[$s[$i]]){
                    $map[$s[$i]] = 1;
                }else {
                    $map[$s[$i]]++;
                }
                if($map[$s[$i]] == 0){
                    unset($map[$s[$i]]);
                }
                if(!$map[$t[$i]]){
                    $map[$t[$i]] = -1;
                }else {
                    $map[$t[$i]]--;
                }
                if($map[$t[$i]] == 0){
                    unset($map[$t[$i]]);
                }

            }

            return !$map? true:false;
        }

        /**
         * 258. 各位相加
         * @param Integer $num
         * @return Integer
         */
        function addDigits258($num) {
            return (($num-1) % 9)+1;
        }

        /**
         * 263. 丑数
         * @param Integer $n
         * @return Boolean
         */
        function isUgly263($n) {
            if($n <= 0){
                return false;
            }
            while($n > 0){
                if($n % 5 == 0){
                    $n = $n / 5;
                    continue;
                }
                if($n % 3 == 0){
                    $n = $n / 3;
                    continue;
                }
                if($n % 2 == 0){
                    $n = $n / 2;
                    continue;
                }
                break;
            }

            return $n == 1?true:false;
        }

        /**
         * 268. 丢失的数字
         * @param Integer[] $nums
         * @return Integer
         */
        function missingNumber268($nums) {
            $sum = 0;
            $count = 0;
            foreach($nums as $num) {
                $sum += $num;
                $count++;
            }

            return((1+$count)*$count/2) - $sum;
        }

        /**
         * 278. 第一个错误的版本
         * @param Integer $n
         * @return Integer
         */
        function firstBadVersion278($n) {
            $start = 1;
            $end   = $n;
            $half = intval(($start+$end)/2);
            while($start <= $end) {
                $half = intval(($start+$end)/2);
                if($this->isBadVersion($half)){
                    if(!$this->isBadVersion($half-1)){
                        return $half;
                    }
                    $end = $half;
                }else{
                    $start = $half+1;
                }
            }

            return $half;
        }
        function isBadVersion($n){
            $x = 1;
            if($n >= $x){
                return true;
            }else{
                return false;
            }
        }

        /**
         * 283. 移动零
         * @param Integer[] $nums
         * @return NULL
         */
        function moveZeroes283(&$nums) {
            $count = 0;
            foreach($nums as $key => &$num) {
                if($num == 0){
                    unset($nums[$key]);
                    $count++;
                }
            }
            for($i = 0; $i < $count; $i++) {
                $nums[] = 0;
            }
        }

        /**
         * 290. 单词规律
         * @param String $pattern
         * @param String $s
         * @return Boolean
         */
        function wordPattern290($pattern, $s) {
            $map  = [];
            $map2 = [];
            $x = 0;
            for($i = 0; $i < strlen($pattern); $i++) {
                if(!$s[$x]){
                    return false;
                }
                print_r($map);
                $str = '';
                while($s[$x] && $s[$x] != ' '){
                    $str .= $s[$x];
                    $x++;
                }
                if(!$map[$pattern[$i]]){
                    $map[$pattern[$i]] = $str;
                    if($map2[$str]){
                        return false;
                    }
                    $map2[$str] = $pattern[$i];
                }else if ($map[$pattern[$i]] != $str){
                    return false;
                }
                $x++;
            }
            if($s[$x]){
                return false;
            }
            return true;
        }

        /**
         * 292. Nim 游戏
         * @param Integer $n
         * @return Boolean
         */
        function canWinNim292($n) {
            if($n % 4 != 0){
                return true;
            }
            return false;
        }





    }

    $solution = new Solution();
    $n = 12;
    print_r($solution->canWinNim292($n));



?>